﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UFIDA.U9.Cust.U9Demo.DeliveryBP
{
   public static class  CreateAPApplyHeadExtend
    {
        /// <summary>
        /// 同币种核销成功的案例：借方为付款单；贷方为应付单
        /// </summary>
        public static void CreateAPApplyHead()
        {
            UFIDA.U9.AP.APApply.Proxy.APApplyProcessProxy processProxy = new AP.APApply.Proxy.APApplyProcessProxy();
            processProxy.IsDiffCurApply = false;
            processProxy.CurExRateDTO = new CBO.FI.DTOs.CurExRateDTOData();
            processProxy.CurExRateDTO.Currency = 1;
            processProxy.CurExRateDTO.ExRate = 1;
            processProxy.IsThrowException = true;
          
            //processProxy.DiffCurApplyDTO = new CBO.FI.DTOs.DiffCurApplyDTOData();
            processProxy.ApplyModes = 1;//枚举SupplierVerificationModesEnum
            processProxy.Supplier = new CBO.SCM.Supplier.SupplierMISCInfoData();
            processProxy.Supplier.Code = "001";
            processProxy.Suppliersite = new CBO.SCM.Supplier.SupplierSiteMISCInfoData();
            processProxy.Suppliersite.Code = "001";
            processProxy.ApplyReadyDTO = new CBO.FI.DTOs.ApplyReadyDTOData();
       

            //借方核销数据 8552
            processProxy.ApplyReadyDTO.DRApplyDTOs = new List<CBO.FI.DTOs.ComingApplyDataDTOData>();
            {
                CBO.FI.DTOs.ComingApplyDataDTOData drDTRO = new CBO.FI.DTOs.ComingApplyDataDTOData();

                drDTRO.ApplyDocType = 3;//应付单，枚举；ApplyDocTypeEnum（PayBill:付款单）
                drDTRO.APSrcDocType = -1;//APBillSrcDocTypeEnum 枚举:应付核销传值-1即可
                drDTRO.ARSrcDocType = 0;//ARBillSrcDocTypeEnum 枚举（SO：销售订单）
                drDTRO.BusinessType = 102;//BusinessTypeEnum 枚举（AP_Payment:付款单）
                drDTRO.CanApplyMoney = 1999990.00M;//（TotalMoney- CurrentApplyMoney)
                drDTRO.CanApplyMoney = 0; //不明白的字段，值为0
                drDTRO.CanEnjoyDiscount = 0;//不明白的字段，值为0
                drDTRO.CurrentApplyMoney = 10;//核销金额
                drDTRO.CurrentApplyEnjoyDiscount = 0; //不明白的字段
                drDTRO.CurrentApplyMCMoney = 0;//不明白的字段
                drDTRO.DataDate = Convert.ToDateTime("2015-08-03");
                drDTRO.DataNo = "Pay-2015080005";
                drDTRO.DocCurrency = new Base.Currency.CurrencyData();
                drDTRO.DocCurrency.ID = 1;
                drDTRO.DocDataTag = 1001508152682481;//付款单用途行
                drDTRO.DocExRate = 1;
                drDTRO.DocExRateType = -1;//ExchangeRateTypesEnum：汇率类型，传值-1
                drDTRO.DocLineTag = 1001508152682480;//付款单行
                drDTRO.DocOrderNo = 0;//不明白的字段，值为0
                drDTRO.DocTag = 1001508152682479;//付款单头ID
                drDTRO.ItemInfo = new CBO.SCM.Item.ItemInfoData();//可以为空
                //drDTRO.Project = 0;//项目为空
                drDTRO.PriorityGrade = 0;//PriorityGradeEnum枚举，优先等级， （A，值为0）
                drDTRO.SrcPreRecType = 0;//RecTypeEnum枚举:收款类型（CustomerRec:客户收款）
                //其他Src字段全部为0或者空值。
                drDTRO.TotalMoney = 2000000.000000000M;
                drDTRO.TotalMoneyBalance = 1999990.000000000M;
                drDTRO.TotalMoneyBalanceFC = 1999990.000000000M;
                drDTRO.TotalMoneyBalanceOfDeposit = 0;//不明白什么意思，传0 
                drDTRO.SysVer = -1;
                processProxy.ApplyReadyDTO.DRApplyDTOs.Add(drDTRO);
            }
            //贷方核销数据
            processProxy.ApplyReadyDTO.CRApplyDTOs = new List<CBO.FI.DTOs.ComingApplyDataDTOData>();
            {
                CBO.FI.DTOs.ComingApplyDataDTOData crDTRO = new CBO.FI.DTOs.ComingApplyDataDTOData();
                crDTRO.APSrcDocType = -1;//APBillSrcDocTypeEnum 枚举；应付核销传值-1
                crDTRO.ARSrcDocType = 0;//ARBillSrcDocTypeEnum 枚举（SO：销售订单）

                crDTRO.ApplyDataNum = 7;//这个7不明白？？？
                crDTRO.ApplyDocType = 1;//枚举；ApplyDocTypeEnum（APBill:应付单）

                crDTRO.BusinessType = 186;//BusinessTypeEnum 枚举（AP_Invoice:采购发票）
                crDTRO.CanApplyMoney = 40.00000000M;
                crDTRO.CurrentApplyMoney = 10;
                crDTRO.DataDate = Convert.ToDateTime("2015-07-30");
                crDTRO.DataNo = "AP-2015070034";
                crDTRO.DocCurrency = new Base.Currency.CurrencyData();
                crDTRO.DocCurrency.ID = 1;
                crDTRO.DocDataTag = 1001508177726563;//应付单分期付款行
                crDTRO.DocExRate = 1;
                crDTRO.DocLineTag = 0;
                crDTRO.DocOrderNo = 1;
                crDTRO.DocTag = 1001508177726563;
                crDTRO.PriorityGrade = 4;//PriorityGradeEnum枚举 值E
                crDTRO.SrcPreRecType = 0;//RecTypeEnum枚举（CustomerRec:客户收款）
                crDTRO.TotalMoney = 50.000000000M;
                crDTRO.TotalMoneyBalance = 40.000000000M;
                crDTRO.TotalMoneyBalanceFC = 40.000000000M;
                crDTRO.SysVer = -1;

                processProxy.ApplyReadyDTO.CRApplyDTOs.Add(crDTRO);
            }

            CBO.FI.DTOs.ApplyProcessDTOData data = processProxy.Do();
           if(data.ApplyRltDTO != null)
            {
                foreach(CBO.FI.DTOs.ApplyResultDTOData resultData in data.ApplyRltDTO)
                {
                    resultData.CRSysVer = -1;
                    resultData.DRSysVer = -1;
                }
            }

            UFIDA.U9.AP.APApply.Proxy.APApplySaveProxy proxy = new AP.APApply.Proxy.APApplySaveProxy();
            proxy.IsDiffCurApply = false;
            proxy.ACMCExRateDTO = new CBO.FI.DTOs.CurExRateDTOData();
            proxy.ACMCExRateDTO.Currency = 1;
            proxy.ACMCExRateDTO.ExRate = 1;
            proxy.ApplyBizDate = Convert.ToDateTime("2020-4-10");
            proxy.ApplyDate = Convert.ToDateTime("2020-4-10");
            proxy.ApplyModes  = 1;//枚举SupplierVerificationModesEnum(按应付单）
            proxy.ApplyOrder = 0;//InvoiceVerificationOrdersEnum枚举(先进先出）
            proxy.ApplyPeriod = 1001507285360916;//记账期间ID
            proxy.ApplyRltDTO = data.ApplyRltDTO;
            //proxy.ApplyRltDTO = new List<CBO.FI.DTOs.ApplyResultDTOData>();
            //{
            //    CBO.FI.DTOs.ApplyResultDTOData resultDTO = new CBO.FI.DTOs.ApplyResultDTOData();
            //    resultDTO.ACToFCExRate = 1;
            //    resultDTO.ApplyRltNum = 1;//值为1，不明白什么意思？？？
            //    //应付单
            //    resultDTO.CRApplyDocType = 1;//ApplyDocTypeEnum(APBill:应付单）
            //    resultDTO.CRBC = new Base.Currency.CurrencyData();
            //    resultDTO.CRBC.ID = 1;
            //    //resultDTO.CRDisplay = new CBO.FI.DTOs.OtherContentDTOData();//不知道怎么来的
            //    resultDTO.CRDocDataTag = 1001508177726563;//	应付单分期付款行
            //    resultDTO.CRDocTag = 1001508177726563;
            //    resultDTO.CROCMoney = 10;
            //    resultDTO.CRSysVer = -1;

            //    //付款单

            //    resultDTO.DRApplyDocType = 3;//枚举ApplyDocTypeEnum（PayBill:付款单）
            //    resultDTO.DRBC = new Base.Currency.CurrencyData();
            //    resultDTO.DRBC.ID = 1;
            //    //resultDTO.DRDisplay = new CBO.FI.DTOs.OtherContentDTOData();//不知道怎么来的
            //    resultDTO.DRDocDataTag = 1001508152682481;//付款单用途行
            //    resultDTO.DRDocTag = 1001508152682479;
            //    resultDTO.DROCMoney = 100;
           
            //    resultDTO.DRSysVer = -1;

            //    proxy.ApplyRltDTO.Add(resultDTO);
            //}
            proxy.ApplySrc = 1;//ApplySourceEnum枚举（ManualApply手工核销）
            proxy.DocTypeKey = 1001507241000112;
            proxy.Sup = new CBO.SCM.Supplier.SupplierMISCInfoData();
            proxy.Sup.Code = "001";
            proxy.Sup.Supplier = 1001507248055553;
            proxy.SupSite = new CBO.SCM.Supplier.SupplierSiteMISCInfoData();
            proxy.SupSite.Code = "001";
            proxy.SupSite.SupplierSite = 1001507248055554;
            proxy.IsDecrease = true;
           
            CBO.FI.DTOs.ApplySaveDTOData DATA = proxy.Do();
           
        }

        /// <summary>
        /// 异币种核销成功案例：借方为付款单；贷方为应付单
        /// </summary>
        public static void CreateAPDiffCurApplyHead()
        {
            UFIDA.U9.AP.APApply.Proxy.APApplyProcessProxy processProxy = new AP.APApply.Proxy.APApplyProcessProxy();
            processProxy.IsDiffCurApply = true;
            processProxy.CurExRateDTO = new CBO.FI.DTOs.CurExRateDTOData();
            processProxy.CurExRateDTO.Currency = 1;//借方币种
            processProxy.CurExRateDTO.ExRate = 1;
            processProxy.CurExRateDTO.ExRateType = 0;//ExchangeRateTypesEnum:汇率类型(Buy:买入）
            processProxy.IsThrowException = true;

            //异币种核销处理
            CBO.FI.DTOs.DiffCurApplyDTOData diffCurApplyDTOData = new CBO.FI.DTOs.DiffCurApplyDTOData();
            diffCurApplyDTOData.AllowDiffValue = 0.01M;//这个应该是允许的误差值？？？
            //贷方币种信息
            diffCurApplyDTOData.CRBCToMCRateDTO = new CBO.FI.DTOs.CurExRateDTOData();
            diffCurApplyDTOData.CRBCToMCRateDTO.Currency = 9;//贷方币种
            diffCurApplyDTOData.CRBCToMCRateDTO.ExRate = 7;//应该是汇率
            diffCurApplyDTOData.CRBCToMCRateDTO.ExRateType = 0;//ExchangeRateTypesEnum:汇率类型(Buy:买入）
            //借方币种信息
            diffCurApplyDTOData.DCToMCExRateDTO = new CBO.FI.DTOs.CurExRateDTOData();
            diffCurApplyDTOData.DCToMCExRateDTO.Currency = 1;//借方方币种
            diffCurApplyDTOData.DCToMCExRateDTO.ExRate = 1;//应该是汇率
            diffCurApplyDTOData.DCToMCExRateDTO.ExRateType = 0;//ExchangeRateTypesEnum:汇率类型(Buy:买入）
            //异币种核销误差处理方式
            diffCurApplyDTOData.DiffCurApplyErrorMethod = 0;//DifferentCurencyApplyErrorMethodEnum:异币种核销误差处理方式（Last：最后一笔）
            processProxy.DiffCurApplyDTO = diffCurApplyDTOData;

            processProxy.ApplyModes = 1;//枚举SupplierVerificationModesEnum:供应商核销明细（ByOrder:按应付单）
            processProxy.ApplyOrder = 0;//InvoiceVerificationOrdersEnum：核销顺序（LIFO：先进先出）
            processProxy.Supplier = new CBO.SCM.Supplier.SupplierMISCInfoData();
            processProxy.Supplier.Code = "001";
            processProxy.Suppliersite = new CBO.SCM.Supplier.SupplierSiteMISCInfoData();
            processProxy.Suppliersite.Code = "001";
            processProxy.ApplyReadyDTO = new CBO.FI.DTOs.ApplyReadyDTOData();

            //借方核销数据 8552
            processProxy.ApplyReadyDTO.DRApplyDTOs = new List<CBO.FI.DTOs.ComingApplyDataDTOData>();
            {
                CBO.FI.DTOs.ComingApplyDataDTOData drDTRO = new CBO.FI.DTOs.ComingApplyDataDTOData();

                drDTRO.ApplyDocType = 3;//应付单，枚举；ApplyDocTypeEnum（PayBill:付款单）
                drDTRO.APSrcDocType = -1;//APBillSrcDocTypeEnum 枚举:应付核销传值-1即可
                drDTRO.ARSrcDocType = 0;//ARBillSrcDocTypeEnum 枚举（SO：销售订单）
                drDTRO.ApplyDataNum = 3;//不明白意思???
                drDTRO.BusinessType = 102;//BusinessTypeEnum 枚举（AP_Payment:付款单）
                drDTRO.CanApplyMoney = 1999999.00M;//（TotalMoney- CurrentApplyMoney)
                drDTRO.CanApplyMoney = 0; //不明白的字段，值为0
                drDTRO.CanEnjoyDiscount = 0;//不明白的字段，值为0
                drDTRO.CurrentApplyMoney = 10;//核销金额
                drDTRO.CurrentApplyEnjoyDiscount = 0; //不明白的字段
                drDTRO.CurrentApplyMCMoney = 10;//不明白的字段？？？异币种核销才有值
                drDTRO.DataDate = Convert.ToDateTime("2015-08-03");
                drDTRO.DataNo = "Pay-2015080005";
                drDTRO.DocCurrency = new Base.Currency.CurrencyData();
                drDTRO.DocCurrency.ID = 1;
                drDTRO.DocDataTag = 1001508152682481;//付款单用途行
                drDTRO.DocExRate = 1;
                drDTRO.DocExRateType = -1;//ExchangeRateTypesEnum：汇率类型，传值-1
                drDTRO.DocLineTag = 1001508152682480;//付款单行
                drDTRO.DocOrderNo = 0;//不明白的字段，值为0
                drDTRO.DocTag = 1001508152682479;//付款单头ID
                drDTRO.ItemInfo = new CBO.SCM.Item.ItemInfoData();//可以为空
                drDTRO.OtherContent = new CBO.FI.DTOs.OtherContentDTOData();//传空值，不知道怎么来的
                //drDTRO.Project = 0;//项目为空
                drDTRO.PriorityGrade = 0;//PriorityGradeEnum枚举，优先等级， （A，值为0）
                drDTRO.SrcPreRecType = 0;//RecTypeEnum枚举:收款类型（CustomerRec:客户收款）
                //其他Src字段全部为0或者空值。
                drDTRO.SysVer = -1;//这里可以给单据版本号；
                drDTRO.TotalMoney = 2000000.000000000M;
                drDTRO.TotalMoneyBalance = 1999999.000000000M;
                drDTRO.TotalMoneyBalanceFC = 1999999.000000000M;
                drDTRO.TotalMoneyBalanceOfDeposit = 0;//不明白什么意思，传0 
                processProxy.ApplyReadyDTO.DRApplyDTOs.Add(drDTRO);
            }
            //贷方核销数据
            processProxy.ApplyReadyDTO.CRApplyDTOs = new List<CBO.FI.DTOs.ComingApplyDataDTOData>();
            {
                CBO.FI.DTOs.ComingApplyDataDTOData crDTRO = new CBO.FI.DTOs.ComingApplyDataDTOData();
                crDTRO.APSrcDocType = -1;//APBillSrcDocTypeEnum 枚举；应付核销传值-1
                crDTRO.ARSrcDocType = 0;//ARBillSrcDocTypeEnum 枚举（SO：销售订单）

                crDTRO.ApplyDataNum = 7;//核销数据序号 :这个7不明白？？？
                crDTRO.ApplyDocType = 1;//核销单据类型.枚举；ApplyDocTypeEnum（APBill:应付单）

                crDTRO.BusinessType = 186;//业务类型。BusinessTypeEnum 枚举（AP_Invoice:采购发票）
                crDTRO.CanApplyMoney = 50.00000000M;//可核销金额
                crDTRO.CanEnjoyDiscount = 0;//可享受折扣，传0
                crDTRO.CurrentApplyMoney = 1.43M;//本次核销原币金额
                crDTRO.CurrentApplyMCMoney = 10;//本次核销中间币种金额
                crDTRO.CurrentApplyEnjoyDiscount = 0;//本次核销折扣
                crDTRO.ApplyCMDMMoney = 0;//冲销通知单金额
                crDTRO.MatchBalance = 0;//匹配余额
                crDTRO.MCMatchBalance = 0;//中间币种匹配余额
                crDTRO.DataDate = Convert.ToDateTime("2015-05-5");//数据日期，单据的日期
                crDTRO.DataNo = "AP-2015080014";//数据编号。单据单号
                crDTRO.DocCurrency = new Base.Currency.CurrencyData();
                crDTRO.DocCurrency.ID = 1;
                crDTRO.DocDataTag = 1001508198247789;//单据数据标识。应付单分期付款行
                crDTRO.DocExRate = 6.123500000M;//单据汇率
                crDTRO.DocExRateType = 0;//汇率类型
                crDTRO.DocLineTag = 0;
                crDTRO.DocOrderNo = 1;//单据排序好
                crDTRO.DocTag = 1001508198247789;//单据标识
                crDTRO.PriorityGrade = 4;//优先等级 PriorityGradeEnum枚举 值E
                crDTRO.SrcPreRecType = 0;//RecTypeEnum枚举（CustomerRec:客户收款）
                crDTRO.TotalMoney = 50.000000000M;//总金额
                crDTRO.TotalMoneyBalance = 50.000000000M;//总金额余额
                crDTRO.TotalMoneyBalanceFC = 306.180000000M;//总金额本币余额
                crDTRO.TotalMoneyBalanceOfDeposit = 0;
                crDTRO.SysVer = -1;//这里可以给单据版本号；

                processProxy.ApplyReadyDTO.CRApplyDTOs.Add(crDTRO);
            }

            CBO.FI.DTOs.ApplyProcessDTOData data = processProxy.Do();


            UFIDA.U9.AP.APApply.Proxy.APApplySaveProxy proxy = new AP.APApply.Proxy.APApplySaveProxy();
            proxy.IsDiffCurApply = true;
            proxy.ACMCExRateDTO = new CBO.FI.DTOs.CurExRateDTOData();
            proxy.ACMCExRateDTO.Currency = 1;
            proxy.ACMCExRateDTO.ExRate = 1;
            proxy.DiffCurApplyDTO = processProxy.DiffCurApplyDTO;
            proxy.ApplyBizDate = Convert.ToDateTime("2020-4-10");
            proxy.ApplyDate = Convert.ToDateTime("2020-4-10");
            proxy.ApplyModes = 1;//枚举SupplierVerificationModesEnum(按应付单）
            proxy.ApplyOrder = 0;//InvoiceVerificationOrdersEnum枚举(先进先出）
            proxy.ApplyPeriod = 1001507285360916;//记账期间ID
            proxy.ApplyRltDTO = data.ApplyRltDTO;
           
            proxy.ApplySrc = 1;//ApplySourceEnum枚举（ManualApply手工核销）
            proxy.DocTypeKey = 1001507241000112;
            proxy.Sup = new CBO.SCM.Supplier.SupplierMISCInfoData();
            proxy.Sup.Code = "001";
            proxy.Sup.Supplier = 1001507248055553;
            proxy.SupSite = new CBO.SCM.Supplier.SupplierSiteMISCInfoData();
            proxy.SupSite.Code = "001";
            proxy.SupSite.SupplierSite = 1001507248055554;
            proxy.IsDecrease = true;

            CBO.FI.DTOs.ApplySaveDTOData DATA = proxy.Do();

        }
    }
}
